/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package pl.mwas.proteana.file.parsers;

import java.io.File;
import java.io.IOException;
import pl.mwas.proteana.geneontology.GOTerm;
import pl.mwas.proteana.geneontology.GOTermBuilder;
import pl.mwas.proteana.geneontology.util.GoTermPropertyFactory;

/**
 *
 * @author loskov
 */
public class OboFileParser extends FileParser {

    private boolean goTermStarted;
    private GOTerm goTerm;
    private GOTermBuilder currGOTerm;

    public OboFileParser(String path) throws IOException {
        super(path);
    }

    public OboFileParser(File file) throws IOException {
        super(file);
    }

    @Override
    protected void parseLine(String line) {
        switch (line) {
            case "[Term]":
                startNewGOTerm();
                break;
            case "":
                endGOTerm();
                break;
            default:
                if (goTermStarted) {
                    currGOTerm = new GoTermPropertyFactory().addPropertyTo(currGOTerm, line);
                }
                break;
        }
    }

    private void startNewGOTerm() {
        currGOTerm = new GOTermBuilder();
        goTermStarted = true;
    }

    private void endGOTerm() {
        if (goTermStarted) {
            goTerm = currGOTerm.build();
            parsedOutput.add(goTerm);
            goTermStarted = false;
        }
    }
}
